package com.proxy.static_proxy;

public class Tank implements Movable {

    @Override
    public void move() throws InterruptedException {
        System.out.println("tank move...");
        Thread.sleep(5);
    }

    public static void main(String[] args) throws InterruptedException {
        new TankTimeProxy(
                new TankLogProxy(
                        new Tank()
                )
        ).move();
    }
}

class TankTimeProxy implements Movable{
    Movable m;
    public TankTimeProxy(Movable m){
        this.m = m;
    }
    @Override
    public void move() throws InterruptedException {
        long start = System.currentTimeMillis();
        m.move();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}

class TankLogProxy implements Movable{
    Movable m;
    public TankLogProxy(Movable m){
        this.m = m;
    }
    @Override
    public void move() throws InterruptedException {
        System.out.println("start moving...");
        long start = System.currentTimeMillis();
        m.move();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}

interface Movable{
    void move() throws InterruptedException;
}